//
//  CCKPubMoreTableViewController.m
//  budejieMe
//
//  Created by 韦恺 on 16/8/27.
//  Copyright © 2016年 SuperJJ. All rights reserved.
//

#import "CCKPubMoreTableViewController.h"
#import "CCKPubMoreModel.h"
#import <UIImageView+WebCache.h>
#define PUBLISH_MORE_CELL_ID @"PUBLISH_MORE_CELL_ID"

@interface CCKPubMoreTableViewController ()

@property (copy, nonatomic) NSArray<CCKPubMoreModel *> *dataArray;

@end

@implementation CCKPubMoreTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self tableViewSettings];
}

- (void)tableViewSettings
{
    self.tableView.rowHeight = 45;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:PUBLISH_MORE_CELL_ID];
    self.tableView.backgroundColor = [UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:1.00];
    
    [self setupNavigationBarLeftButton];
}

- (void)setupNavigationBarLeftButton
{
//    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 36)];
//    [leftButton setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
//    [leftButton setTitle:@"返回" forState:UIControlStateNormal];
//    leftButton.titleLabel.font = [UIFont systemFontOfSize:17];
//    
//    [leftButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [leftButton addTarget:self action:@selector(returnLastViewController) forControlEvents:UIControlEventTouchUpInside];
//    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

    
}

- (void)returnLastViewController
{
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setUrlStr:(NSString *)urlStr
{
    [CCKPubMoreModel downloadPubMoreDataWithUrl:urlStr successBlock:^(NSArray *dataArr) {
        
        _dataArray = dataArr;
        [self.tableView reloadData];
        
    } failBlock:^(NSError *error) {
        
        NSLog(@"%s\n\n%@", __FUNCTION__, error);
        
    }];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PUBLISH_MORE_CELL_ID forIndexPath:indexPath];
    
    [cell.contentView addSubview:[self getLineViewWithCell:cell]];
    
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    cell.textLabel.text = _dataArray[indexPath.row].name;
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:_dataArray[indexPath.row].icon]placeholderImage:[UIImage imageNamed:@"publish-offline"]];

    return cell;
}

- (UIView *)getLineViewWithCell:(UITableViewCell *)cell
{
    UIView *lineView = [UIView new];
    lineView.frame = CGRectMake(0, cell.frame.size.height, cell.frame.size.width, 1);
    lineView.backgroundColor = [UIColor grayColor];
    lineView.alpha = 0.3;
    
    return lineView;
}

//- (BOOL)hidesBottomBarWhenPushed
//{
//    return YES;
//}

- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];
 // Dispose of any resources that can be recreated.

}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
